package cn.zwxky.android.user.News;

import android.content.Context;
import android.view.View;

import com.zgscwjm.lsfbbasetemplate.Event.LsfbEvent;
import com.zgscwjm.lsfbbasetemplate.adapter.CommonAdapter;
import com.zgscwjm.lsfbbasetemplate.adapter.ViewHolder;

import java.util.List;

import cn.zwxky.android.user.R;
import cn.zwxky.android.user.Scope.ScopeClickEvent;
import cn.zwxky.android.user.Utils.URLString;

/**
 * Created by Administrator on 2017/3/24 0024.
 */

public class NewsAdapter extends CommonAdapter<NewsBean.ListBean> {
    public NewsAdapter(Context context, int layoutId, List<NewsBean.ListBean> list) {
        super(context, layoutId, list);
    }

    @Override
    public void convert(ViewHolder holder, final NewsBean.ListBean model) {
        holder.setText(R.id.item_news_text_title, model.getTitle());
        holder.setText(R.id.item_news_text_time, model.getTimes());
        String[] img = model.getImg().split(",");
        if (img.length==1){
            holder.setImg(R.id.item_news_img1, URLString.IMG_URL+img[0],R.drawable.img_zhanwei);
            holder.setBackgoundRes(R.id.item_news_img2,R.color.white_color);
            holder.setBackgoundRes(R.id.item_news_img3,R.color.white_color);
        }else if (img.length==2){
            holder.setImg(R.id.item_news_img1, URLString.IMG_URL+img[0],R.drawable.img_zhanwei);
            holder.setImg(R.id.item_news_img2, URLString.IMG_URL+img[1],R.drawable.img_zhanwei);
            holder.setBackgoundRes(R.id.item_news_img3,R.color.white_color);
        }else if (img.length==3){
            holder.setImg(R.id.item_news_img1, URLString.IMG_URL+img[0],R.drawable.img_zhanwei);
            holder.setImg(R.id.item_news_img2, URLString.IMG_URL+img[1],R.drawable.img_zhanwei);
            holder.setImg(R.id.item_news_img3, URLString.IMG_URL+img[2],R.drawable.img_zhanwei);
        }else if (img.length==0){
            holder.setViewVisible(R.id.item_news_img, false);
        }

        holder.setOnclick(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                NewsClickEvent even = new NewsClickEvent();
                even.setData(model.getUrl());
                LsfbEvent.getInstantiation().post(even);
            }
        });

    }
}
